Scope of Subroutine Calls in Tell Statements
If you need to call a subroutine from within a Tell statement, you must use the reserved wordsof me
ormy
to indicate that the subroutine is part of the script--not a command that should be sent to the object of the Tell statement.For example, the
minimumValue
subroutine call in the following Tell statement is unsuccessful, because AppleScript sends theminimumValue
command to the Scriptable Text Editor. (You get an error message saying
that the Scriptable Text Editor does not understand theminimumValue
command.)
tell application "Scriptable Text Editor" minimumValue(12, 400) copy result as string to word 15 of front document end tell (* result: the subroutine call is unsuccessful because AppleScript sends the minimumValue command to the Scriptable Text Editor *)If you use the wordsof
me
in the subroutine call, as shown in the following Tell statement, the subroutine call is successful, because AppleScript knows that the subroutine is part of the script.
tell application "Scriptable Text Editor" minimumValue(12, 400) of me copy result as string to word 15 of front document end tell (* result: the subroutine call is successful because the words "of me" tell AppleScript that the minimumValue command is part of the script *)The wordmy
before the subroutine call is a synonym for the wordsof me
after the subroutine call. For example, the following two subroutine calls are equivalent:
minimumValue(12, 400) of me my minimumValue(12, 400)